var http = require("http");
var fs = require("fs");
var path = require("path");

http.createServer((req, res) => {
    var arg = process.argv[2];
    if(arg != null){
        fs.exists(arg, function(exists){
            if(exists){
                var readPath = path.join(__dirname, arg);
                var readable = fs.createReadStream(readPath);
                res.end(readable);
            }
            if(!exists){
                console.log("文件不存在")
            }
        })
    }else{
        var filePath1 = path.join(__dirname, "/fileReader1.js");
        var readable1 = fs.createReadStream(filePath1);
        res.end(readable1);
    }
}).listen(8081);

console.log("server is listening 8081")